package com.readexcel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.getRulersConditions.GetAll;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {
	int rulernumber = 1;
	public void setRulernumber(int rulernumber) {
		this.rulernumber = rulernumber;
	}
	public void readExcel(File excelFile, int rowNum) throws BiffException,
			IOException {
		GetAll rc = new GetAll(rulernumber);// 1代表规则编号，设置规则初始编号
		Workbook rwb = null;
		Cell cell = null;
		// 创建输入流
		InputStream stream = new FileInputStream(excelFile);
		// 获取Excel文件对象
		rwb = Workbook.getWorkbook(stream);
		// 获取文件的指定工作表 默认的第一个
		for (int s = 0; s < rwb.getNumberOfSheets(); s++) {// 获取excel中有多少个sheet,遍历读取
			List<String[]> list = new ArrayList<String[]>();
			Sheet sheet = rwb.getSheet(s);
			// 行数(表头的目录不需要，从1开始)
			String line = "";
			for (int i = rowNum - 1; i < sheet.getRows(); i++) {
				// 创建一个数组 用来存储每一列的值
				String[] str = new String[sheet.getColumns()];
				// 列数
				for (int j = 0; j < sheet.getColumns(); j++) {
					// 获取第i行，第j列的值
					cell = sheet.getCell(j, i);
					str[j] = cell.getContents();
					line += str[j] + "  ";// 组成一行
				}
				rc.getRulersConditions(line);
				line = "";
			}
		}
		rc.prt();// 写入文件
	}

	public ReadExcel() {
		super();
	}
}
